package com.joker.aigc.tools.controller;

import com.joker.aigc.domain.entity.R;
import com.joker.aigc.tools.domian.dto.CategoryAddDTO;
import com.joker.aigc.tools.domian.dto.CategoryDTO;
import com.joker.aigc.tools.domian.po.ActorsPO;
import com.joker.aigc.tools.service.video.CategoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 分类控制器
 *
 * @author system
 * @date 2023-12-01
 */
@Tag(name = "分类管理", description = "视频分类相关接口")
@RestController
@RequestMapping("/api/categories")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 获取所有分类
     *
     * @return 分类列表
     */
    @Operation(
            summary = "获取所有分类",
            description = "获取系统中所有的分类信息，包含子分类",
            responses = {
                    @ApiResponse(responseCode = "200", description = "获取成功"),
                    @ApiResponse(responseCode = "500", description = "服务器内部错误")
            }
    )
    @GetMapping
    public R<List<CategoryDTO>> getAllCategories() {
        List<CategoryDTO> categories = categoryService.getAllCategories();
        return R.ok(categories);
    }

    /**
     * 根据类型获取分类
     *
     * @param type 分类类型 (genre/region/actor)
     * @return 分类列表
     */
    @Operation(
            summary = "根据类型获取分类",
            description = "根据分类类型获取对应的分类列表",
            responses = {
                    @ApiResponse(responseCode = "200", description = "获取成功"),
                    @ApiResponse(responseCode = "400", description = "分类类型不支持"),
                    @ApiResponse(responseCode = "500", description = "服务器内部错误")
            }
    )
    @GetMapping("/{type}")
    public R<List<CategoryDTO>> getCategoriesByType(String type) {
        List<CategoryDTO> categories = categoryService.getCategoriesByType(type);
        return R.ok(categories);
    }

    /**
     * 获取子分类
     *
     * @param categoryId 分类ID
     * @return 子分类列表
     */
    @Operation(
            summary = "获取子分类",
            description = "根据分类ID获取对应的子分类列表",
            responses = {
                    @ApiResponse(responseCode = "200", description = "获取成功"),
                    @ApiResponse(responseCode = "404", description = "分类不存在"),
                    @ApiResponse(responseCode = "500", description = "服务器内部错误")
            }
    )
    @GetMapping("/subcategories/{categoryId}")
    public R<List<CategoryDTO.SubCategoryDTO>> getSubCategories(Long categoryId) {
        List<CategoryDTO.SubCategoryDTO> subCategories = categoryService.getSubCategories(categoryId);
        return R.ok(subCategories);
    }


    /**
     * 获取演员列表
     *
     * @param actorName 演员名称
     * @return 演员列表
     */
    @GetMapping("/actors")
    public R<List<ActorsPO>> getActors(String actorName) {
        List<ActorsPO> actors = categoryService.getActors(actorName);
        return R.ok(actors);
    }

    @PostMapping("/add")
    public R<String> addCategory(@RequestBody CategoryAddDTO categoryAddDTO) {
        return R.ok(categoryService.addCategory(categoryAddDTO));
    }
} 